/*
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2014
 *
 * fileName:  ReckonTimes.java
 * author:  lei
 * Company:  Cloudland Studio
 * Createdate:  2013-9-14 上午10:00:07
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2013-9-14          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.util;

import java.util.Calendar;
import java.util.HashMap;

 /**
 * <pre> 
 * 用于测试阶段提供的计时器
 * </pre>
 * @ClassName  ReckonTimes
 * @author  lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
public class ReckonTimes {
private static ThreadLocal<HashMap<String, Long>> RECKON = new ThreadLocal<HashMap<String, Long>>();
    
    /** 
     * doStart 开始计时
     *
     * @param reckonName 计时器名称
     */
    public static void doStart(final String reckonName) {
        HashMap<String, Long> map = null;
        if (null == RECKON.get()) {
            map = new HashMap<String, Long>();
            RECKON.set(map);
        }
        RECKON.get().put(reckonName, Calendar.getInstance().getTimeInMillis());
    }
    
    /** 
     * doEnd 结束计时
     *
     * @param reckonName 计时器名称
     * @return 
     */
    public static long doEnd(final String reckonName) {
        long end = Calendar.getInstance().getTimeInMillis();
        return end - RECKON.get().get(reckonName);
    }
}
